﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using LotroTweeter.Data;

namespace LotroTweeter.Engine
{
    public class DataConverter : IDataConverter
    {
        public KinRoster ConvertKinRoster(XElement kinRoster)
        {
            var guild = kinRoster.Descendants("guild").FirstOrDefault();
            var roster = new KinRoster
                {
                    MemberCount = (int)guild.Attribute("memberCount"),
                    Name = (string)guild.Attribute("name"),
                    Theme = (string)guild.Attribute("theme"),
                    World = (string)guild.Attribute("world")
                };

            var result = from e in kinRoster.Descendants("character")
                          select new KinMember
                          {
                              Class = (string)e.Attribute("class"),
                              Level = (int)e.Attribute("level"),
                              Name = (string)e.Attribute("name"),
                              Race = (string)e.Attribute("race"),
                              Rank = (string)e.Attribute("rank")
                          };
            roster.Members = result.AsEnumerable();
            return roster;
        }
    }
}
